package com.applink.sell_proof.model;

import java.util.ArrayList;

import com.applink.sell_proof.pojo.GenericAttribute;
import com.applink.sell_proof.share.Parameter;
import com.applink.sell_proof.utilXMLParser.ObjPropInfo;

public class NewRewardProjectDetail {
	private String InvoiceNo;
	private String InvoiceDate;
	private String OpportunityName;
	private String CustomerCompany;
	private String Amount;
	private String ObjectID;
	private String RewardType;
	public String getInvoiceNo() {
		return InvoiceNo;
	}
	public void setInvoiceNo(String invoiceNo) {
		InvoiceNo = invoiceNo;
	}
	public String getInvoiceDate() {
		return InvoiceDate;
	}
	public void setInvoiceDate(String invoiceDate) {
		InvoiceDate = invoiceDate;
	}
	public String getOpportunityName() {
		return OpportunityName;
	}
	public void setOpportunityName(String opportunityName) {
		OpportunityName = opportunityName;
	}
	public String getCustomerCompany() {
		return CustomerCompany;
	}
	public void setCustomerCompany(String customerCompany) {
		CustomerCompany = customerCompany;
	}
	public String getAmount() {
		return Amount;
	}
	public void setAmount(String amount) {
		Amount = amount;
	}
	public String getObjectID() {
		return ObjectID;
	}
	public void setObjectID(String objectID) {
		ObjectID = objectID;
	}
	public String getRewardType() {
		return RewardType;
	}
	public void setRewardType(String rewardType) {
		RewardType = rewardType;
	}
	
	
	@SuppressWarnings("rawtypes")
	public ArrayList<GenericAttribute> convertIntoGenericAttributes(
			ArrayList<ObjPropInfo> objPropListDetail) {
		
		ArrayList<GenericAttribute> attributeList = new ArrayList<GenericAttribute>();
		
		for(int i=0; i< objPropListDetail.size();i++){
			ObjPropInfo objPropInfo =objPropListDetail.get(i);
    		
    		String name = objPropInfo.getOPID();
    		String dataType = objPropInfo.getDataType();
    		
    		String value = this.getValueByName(name);
    		
    		if(value == ""){
    			value = "0";
    		}
    		if(dataType.compareTo(Parameter.TYPE_INT) == 0) {
    			GenericAttribute<String, Integer> attribute = new GenericAttribute<String, Integer>(name, (int) Long.parseLong(value));
    			attributeList.add(attribute);
    		} else if (dataType.compareTo(Parameter.TYPE_CHAR) == 0){
    			GenericAttribute<String, String> attribute = new GenericAttribute<String, String>(name, String.valueOf(value));
    			attributeList.add(attribute);
    		} else if (dataType.compareTo(Parameter.TYPE_DOUBLE) == 0){
    			GenericAttribute<String, Double> attribute = new GenericAttribute<String, Double>(name, Double.parseDouble(value));           			
    			attributeList.add(attribute);
    		}
    	
		}
		
		return  attributeList;
	}	
	
	

	public String getValueByName(String name){
		
		String value="";
		Object instance;
		try {
			instance = getClass().getDeclaredField(name).get(this);
			value = instance.toString();
		} catch (Exception e) {
			value = "";
		}
		return value;
	}
}
